package cn.itcast.bos.service.take_delivery.impl;

import cn.itcast.bos.dao.take_delivery.PromotionRepository;
import domain.page.PageBean;
import domain.take_delivery.Promotion;
import cn.itcast.bos.service.take_delivery.PromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created by Administrator on 2017/7/21/021.
 */
@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {

    @Autowired
    PromotionRepository promotionRepository;

    @Override
    public Page<Promotion> findAll(Specification<Promotion> spec, Pageable pageable) {
        return null;
    }



    @Override
    public void save(Promotion entity) {
        promotionRepository.save(entity);
    }

    @Override
    public Page<Promotion> findAll(Pageable pageable) {
        return promotionRepository.findAll(pageable);
    }

    @Override
    public PageBean<Promotion> findPageData(int page, int rows) {
        System.out.println(page+"..........."+rows);
        Pageable pageable= new PageRequest(page-1,rows);
        Page<Promotion> all = promotionRepository.findAll(pageable);
        PageBean<Promotion> pageBean = new PageBean<>();
        pageBean.setTotalCount(all.getTotalElements());
        pageBean.setPageData(all.getContent());
        return pageBean;
    }

    @Override
    public Promotion findById(Integer id) {
        return promotionRepository.findById(id);
    }

    @Override
    public void updateStatus(Date date) {
        promotionRepository.updateStatus(date);
    }
}
